package com.yixiang.np.mapper.impl;

import com.yixiang.np.mapper.BaseService;
import com.yixiang.np.mapper.NoticeMapperService;
import com.yixiang.np.model.po.PltmNotice;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created by Administrator on 2016/11/1.
 */
@Service("noticeMapperService")
public class NoticeMapperServiceImpl extends BaseService<PltmNotice, Long> implements NoticeMapperService {
    @Override
    public Integer create(PltmNotice record) {
        return mapper.insertSelective(record);
    }

    @Override
    public Integer updateById(PltmNotice record) {
        Example example = new Example(PltmNotice.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("id", record.getId());
        return mapper.updateByExampleSelective(record, example);
    }

    @Override
    public List<PltmNotice> listByCondition(PltmNotice record, String orderBy) {
        Example example = new Example(PltmNotice.class);
        Example.Criteria criteria = example.createCriteria();
        if (record != null) {
            if (record.getId() != null) {
                criteria.andEqualTo("id", record.getId());
            }
            if (record.getStatus() != null) {
                criteria.andEqualTo("status", record.getStatus());
            }
        }
        if (StringUtils.isNotEmpty(orderBy)) {
            example.setOrderByClause(orderBy);
//            example.orderBy(orderBy);
        }
        return super.mapper.selectByExample(example);
    }

    @Override
    public Integer delete(PltmNotice pltmNotice) {
        return super.mapper.deleteByPrimaryKey(pltmNotice.getId());
    }

    @Override
    public PltmNotice read(PltmNotice pltmNotice) {
        return super.mapper.selectOne(pltmNotice);
    }


}
